package com.epoint.mobileoa.ui.toolview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;

/**
 * @author liyc
 * @time 2012-8-9 下午1:42:53
 * @annotation 
 */
public class Tool9ggView extends SuperView {

	private GridView gv;
	private String[] classesName;

	@Override
	public void initControls() {
		Intent intent = getIntent();
		String viewtitle = intent.getStringExtra("viewtitle");
		top_title.setText(viewtitle);
		String[] titles = intent.getStringArrayExtra("titles");

		classesName = intent.getStringArrayExtra("classesName");

		int[] imgs = intent.getIntArrayExtra("imgs");

		gv = (GridView) findViewById(R.id.gv);
		gv.setOnItemClickListener(this);
		gv.setAdapter(getAdapter(titles,imgs));
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		String intentClassName = classesName[position];
		try {
			Class<?> clazz =Class.forName(intentClassName);
			Intent intent = new Intent(Tool9ggView.this,clazz);
			startActivity(intent);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void refresh(Object... param) {

	}

	@Override
	public int getLayoutInt() {
		return R.layout.gzrzmain;
	}

	public SimpleAdapter getAdapter(String[] titles,int[] imgs){
		List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < imgs.length; i++) {
			Map<String, Object> mapItem = new HashMap<String, Object>();
			mapItem.put("img", imgs[i]);
			mapItem.put("title", titles[i]);
			listItems.add(mapItem);
		}

		int iconlayout;
		if(getBackgroundStr().equals("white")){
			iconlayout = R.layout.gvicon;
		}
		else{
			iconlayout = R.layout.gvicon_white;
		}

		SimpleAdapter sa = new SimpleAdapter(this, listItems, iconlayout,
				new String[] { "img", "title" }, new int[] { R.id.gvicon_img,
				R.id.gvicon_title });
		return sa;
	}

	@Override
	public void refreshForNewTask(int TaskId,Object... param) {
	}

}
